using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Diagnostics;
using SharePoint.ImportExport.Core;
using GotDotNet.SharePointExtractor;
using System.Globalization;

namespace GUISharePointExtractor
{
	/// <summary>
	/// Summary description for frmSharePointExtractor.
	/// </summary>
	public class formSharePointExtractor : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl Settings;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.Button btnNext1;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.RichTextBox rtb_EventLog;
		private System.Windows.Forms.RadioButton rdReportErrors;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtOutputDirectory;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox txtSiteURL;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cmbSiteType;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtRoot;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtNewName;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox cmbDestSiteType;
		private System.Windows.Forms.CheckBox chkSiteDir;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.CheckBox chkExtractDesign;
		private System.Windows.Forms.CheckBox chkExtractUsers;
		private System.Windows.Forms.CheckBox chkExtractSubSites;
		private System.Windows.Forms.TextBox txtList;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txtFolder;
        private System.Windows.Forms.Label label8;
		private System.Windows.Forms.CheckBox chkVersions;
		private System.Windows.Forms.CheckBox chkExtractDocLibsOnly;
        private CheckBox chkProcessGalleries;
        private CheckBox chkUseTimeThreshold;
        private DateTimePicker dtThreshhold;
        private CheckBox chkExtractViews;

		string configFile;

		/// <summary>
		/// Thia 
		/// </summary>
		public formSharePointExtractor()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			configFile=Application.StartupPath+"\\Config.dat";
			cmbSiteType.SelectedIndex=0;
			cmbDestSiteType.SelectedIndex=0;
			
			dtThreshhold.CustomFormat =  Application.CurrentCulture.DateTimeFormat.ShortDatePattern+" " +Application.CurrentCulture.DateTimeFormat.ShortTimePattern;



			try 
			{
				// Create an instance of StreamReader to read from a file.
				// The using statement also closes the StreamReader.
				using(StreamReader sr = new StreamReader(configFile))
				{
					String line=sr.ReadLine();
					txtSiteURL.Text=line;
					line=sr.ReadLine();
					txtNewName.Text=line;
					line=sr.ReadLine();
					txtOutputDirectory.Text=line;
					line=sr.ReadLine();
					txtRoot.Text=line;
					line=sr.ReadLine();
					cmbSiteType.Text=line;
					line=sr.ReadLine();
					cmbDestSiteType.Text=line;
					line=sr.ReadLine();
					txtFolder.Text=line;
					line=sr.ReadLine();
					//=line;
					line=sr.ReadLine();
					chkExtractDesign.Checked=bool.Parse(line);
					line=sr.ReadLine();
					chkExtractUsers.Checked=bool.Parse(line);
					line=sr.ReadLine();
					txtList.Text=line;
					line=sr.ReadLine();
					chkExtractSubSites.Checked=bool.Parse(line);
					line=sr.ReadLine();
					chkSiteDir.Checked=bool.Parse(line);
					line=sr.ReadLine();
					chkUseTimeThreshold.Checked=bool.Parse(line);
					line=sr.ReadLine();
					dtThreshhold.Value=DateTime.Parse(line);
					line=sr.ReadLine();
					chkVersions.Checked=bool.Parse(line);
					line=sr.ReadLine();
					chkExtractDocLibsOnly.Checked=bool.Parse(line);

			
				}
			}
			catch (ArgumentException argEx) 
			{
				Logger.Log(ErrorLevel.NoLog,"Error :"+argEx.Message);
			}
			catch (IOException e) 
			{
				// Let the user know what went wrong.
				Console.WriteLine("The file could not be read:");
				Console.WriteLine(e.Message);
			}
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(formSharePointExtractor));
            this.Settings = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.dtThreshhold = new System.Windows.Forms.DateTimePicker();
            this.chkUseTimeThreshold = new System.Windows.Forms.CheckBox();
            this.chkExtractViews = new System.Windows.Forms.CheckBox();
            this.chkProcessGalleries = new System.Windows.Forms.CheckBox();
            this.chkExtractDocLibsOnly = new System.Windows.Forms.CheckBox();
            this.txtList = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.txtFolder = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.chkExtractDesign = new System.Windows.Forms.CheckBox();
            this.chkExtractUsers = new System.Windows.Forms.CheckBox();
            this.chkExtractSubSites = new System.Windows.Forms.CheckBox();
            this.chkVersions = new System.Windows.Forms.CheckBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.chkSiteDir = new System.Windows.Forms.CheckBox();
            this.cmbDestSiteType = new System.Windows.Forms.ComboBox();
            this.label6 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.txtRoot = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtNewName = new System.Windows.Forms.TextBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.cmbSiteType = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtSiteURL = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.btnNext1 = new System.Windows.Forms.Button();
            this.label5 = new System.Windows.Forms.Label();
            this.txtOutputDirectory = new System.Windows.Forms.TextBox();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.btnClose = new System.Windows.Forms.Button();
            this.btnStart = new System.Windows.Forms.Button();
            this.rtb_EventLog = new System.Windows.Forms.RichTextBox();
            this.rdReportErrors = new System.Windows.Forms.RadioButton();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.Settings.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.tabPage2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // Settings
            // 
            this.Settings.Controls.Add(this.tabPage1);
            this.Settings.Controls.Add(this.tabPage2);
            this.Settings.Location = new System.Drawing.Point(8, 72);
            this.Settings.Name = "Settings";
            this.Settings.SelectedIndex = 0;
            this.Settings.Size = new System.Drawing.Size(548, 440);
            this.Settings.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.groupBox3);
            this.tabPage1.Controls.Add(this.groupBox2);
            this.tabPage1.Controls.Add(this.groupBox1);
            this.tabPage1.Controls.Add(this.btnNext1);
            this.tabPage1.Controls.Add(this.label5);
            this.tabPage1.Controls.Add(this.txtOutputDirectory);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Size = new System.Drawing.Size(540, 414);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Settings";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.dtThreshhold);
            this.groupBox3.Controls.Add(this.chkUseTimeThreshold);
            this.groupBox3.Controls.Add(this.chkExtractViews);
            this.groupBox3.Controls.Add(this.chkProcessGalleries);
            this.groupBox3.Controls.Add(this.chkExtractDocLibsOnly);
            this.groupBox3.Controls.Add(this.txtList);
            this.groupBox3.Controls.Add(this.label7);
            this.groupBox3.Controls.Add(this.txtFolder);
            this.groupBox3.Controls.Add(this.label8);
            this.groupBox3.Controls.Add(this.chkExtractDesign);
            this.groupBox3.Controls.Add(this.chkExtractUsers);
            this.groupBox3.Controls.Add(this.chkExtractSubSites);
            this.groupBox3.Controls.Add(this.chkVersions);
            this.groupBox3.Location = new System.Drawing.Point(0, 88);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(526, 130);
            this.groupBox3.TabIndex = 1;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Selection";
            // 
            // dtThreshhold
            // 
            this.dtThreshhold.AllowDrop = true;
            this.dtThreshhold.Enabled = false;
            this.dtThreshhold.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            this.dtThreshhold.Location = new System.Drawing.Point(320, 103);
            this.dtThreshhold.Name = "dtThreshhold";
            this.dtThreshhold.Size = new System.Drawing.Size(143, 20);
            this.dtThreshhold.TabIndex = 12;
            // 
            // chkUseTimeThreshold
            // 
            this.chkUseTimeThreshold.Location = new System.Drawing.Point(320, 74);
            this.chkUseTimeThreshold.Name = "chkUseTimeThreshold";
            this.chkUseTimeThreshold.Size = new System.Drawing.Size(104, 23);
            this.chkUseTimeThreshold.TabIndex = 9;
            this.chkUseTimeThreshold.Text = "Restrict by date";
            this.chkUseTimeThreshold.CheckedChanged += new System.EventHandler(this.chkUseTimeThreshold_CheckedChanged_1);
            // 
            // chkExtractViews
            // 
            this.chkExtractViews.AutoSize = true;
            this.chkExtractViews.Location = new System.Drawing.Point(190, 74);
            this.chkExtractViews.Name = "chkExtractViews";
            this.chkExtractViews.Size = new System.Drawing.Size(90, 17);
            this.chkExtractViews.TabIndex = 8;
            this.chkExtractViews.Text = "Extract Views";
            this.chkExtractViews.UseVisualStyleBackColor = true;
            // 
            // chkProcessGalleries
            // 
            this.chkProcessGalleries.AutoSize = true;
            this.chkProcessGalleries.Location = new System.Drawing.Point(16, 97);
            this.chkProcessGalleries.Name = "chkProcessGalleries";
            this.chkProcessGalleries.Size = new System.Drawing.Size(107, 17);
            this.chkProcessGalleries.TabIndex = 10;
            this.chkProcessGalleries.Text = "Process &Galleries";
            this.chkProcessGalleries.UseVisualStyleBackColor = true;
            // 
            // chkExtractDocLibsOnly
            // 
            this.chkExtractDocLibsOnly.Location = new System.Drawing.Point(320, 40);
            this.chkExtractDocLibsOnly.Name = "chkExtractDocLibsOnly";
            this.chkExtractDocLibsOnly.Size = new System.Drawing.Size(178, 36);
            this.chkExtractDocLibsOnly.TabIndex = 6;
            this.chkExtractDocLibsOnly.Text = "Extract Only Document Libraries";
            // 
            // txtList
            // 
            this.txtList.Location = new System.Drawing.Point(128, 19);
            this.txtList.Name = "txtList";
            this.txtList.Size = new System.Drawing.Size(100, 20);
            this.txtList.TabIndex = 1;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(13, 19);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(100, 20);
            this.label7.TabIndex = 0;
            this.label7.Text = "List/Library";
            // 
            // txtFolder
            // 
            this.txtFolder.Location = new System.Drawing.Point(320, 19);
            this.txtFolder.Name = "txtFolder";
            this.txtFolder.Size = new System.Drawing.Size(112, 20);
            this.txtFolder.TabIndex = 3;
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(256, 19);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(48, 20);
            this.label8.TabIndex = 2;
            this.label8.Text = "Folder";
            // 
            // chkExtractDesign
            // 
            this.chkExtractDesign.Checked = true;
            this.chkExtractDesign.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkExtractDesign.Location = new System.Drawing.Point(190, 45);
            this.chkExtractDesign.Name = "chkExtractDesign";
            this.chkExtractDesign.Size = new System.Drawing.Size(104, 24);
            this.chkExtractDesign.TabIndex = 5;
            this.chkExtractDesign.Text = "Extract Design";
            // 
            // chkExtractUsers
            // 
            this.chkExtractUsers.Checked = true;
            this.chkExtractUsers.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkExtractUsers.Location = new System.Drawing.Point(16, 67);
            this.chkExtractUsers.Name = "chkExtractUsers";
            this.chkExtractUsers.Size = new System.Drawing.Size(104, 24);
            this.chkExtractUsers.TabIndex = 7;
            this.chkExtractUsers.Text = "Extract Users";
            // 
            // chkExtractSubSites
            // 
            this.chkExtractSubSites.Checked = true;
            this.chkExtractSubSites.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkExtractSubSites.Location = new System.Drawing.Point(16, 45);
            this.chkExtractSubSites.Name = "chkExtractSubSites";
            this.chkExtractSubSites.Size = new System.Drawing.Size(168, 24);
            this.chkExtractSubSites.TabIndex = 4;
            this.chkExtractSubSites.Text = "Extract Subsites/subareas";
            // 
            // chkVersions
            // 
            this.chkVersions.Location = new System.Drawing.Point(190, 103);
            this.chkVersions.Name = "chkVersions";
            this.chkVersions.Size = new System.Drawing.Size(128, 23);
            this.chkVersions.TabIndex = 11;
            this.chkVersions.Text = "Extract &Versions";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.chkSiteDir);
            this.groupBox2.Controls.Add(this.cmbDestSiteType);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.label3);
            this.groupBox2.Controls.Add(this.txtRoot);
            this.groupBox2.Controls.Add(this.label4);
            this.groupBox2.Controls.Add(this.txtNewName);
            this.groupBox2.Location = new System.Drawing.Point(0, 224);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(526, 117);
            this.groupBox2.TabIndex = 2;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Target";
            // 
            // chkSiteDir
            // 
            this.chkSiteDir.Location = new System.Drawing.Point(320, 88);
            this.chkSiteDir.Name = "chkSiteDir";
            this.chkSiteDir.Size = new System.Drawing.Size(152, 24);
            this.chkSiteDir.TabIndex = 6;
            this.chkSiteDir.Text = "Show in Site Directory";
            // 
            // cmbDestSiteType
            // 
            this.cmbDestSiteType.Items.AddRange(new object[] {
            "Site",
            "Area"});
            this.cmbDestSiteType.Location = new System.Drawing.Point(128, 88);
            this.cmbDestSiteType.Name = "cmbDestSiteType";
            this.cmbDestSiteType.Size = new System.Drawing.Size(121, 21);
            this.cmbDestSiteType.TabIndex = 5;
            this.cmbDestSiteType.Text = "Site";
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(16, 88);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(100, 23);
            this.label6.TabIndex = 4;
            this.label6.Text = "Site Type";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(16, 54);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(100, 32);
            this.label3.TabIndex = 2;
            this.label3.Text = "Managed Path (Inclusion) ";
            // 
            // txtRoot
            // 
            this.txtRoot.Location = new System.Drawing.Point(128, 56);
            this.txtRoot.Name = "txtRoot";
            this.txtRoot.Size = new System.Drawing.Size(344, 20);
            this.txtRoot.TabIndex = 3;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(16, 24);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(100, 23);
            this.label4.TabIndex = 0;
            this.label4.Text = "New site name";
            // 
            // txtNewName
            // 
            this.txtNewName.Location = new System.Drawing.Point(128, 24);
            this.txtNewName.Name = "txtNewName";
            this.txtNewName.Size = new System.Drawing.Size(344, 20);
            this.txtNewName.TabIndex = 1;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.cmbSiteType);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.txtSiteURL);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(0, 0);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(526, 88);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Source";
            // 
            // cmbSiteType
            // 
            this.cmbSiteType.Items.AddRange(new object[] {
            "Site",
            "Area"});
            this.cmbSiteType.Location = new System.Drawing.Point(128, 56);
            this.cmbSiteType.Name = "cmbSiteType";
            this.cmbSiteType.Size = new System.Drawing.Size(121, 21);
            this.cmbSiteType.TabIndex = 3;
            this.cmbSiteType.Text = "Site";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(16, 56);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 23);
            this.label2.TabIndex = 2;
            this.label2.Text = "Site Type";
            // 
            // txtSiteURL
            // 
            this.txtSiteURL.Location = new System.Drawing.Point(128, 24);
            this.txtSiteURL.Name = "txtSiteURL";
            this.txtSiteURL.Size = new System.Drawing.Size(344, 20);
            this.txtSiteURL.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(16, 24);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 32);
            this.label1.TabIndex = 0;
            this.label1.Text = "Site URL/XML List of sites";
            // 
            // btnNext1
            // 
            this.btnNext1.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnNext1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnNext1.ForeColor = System.Drawing.SystemColors.Menu;
            this.btnNext1.Location = new System.Drawing.Point(430, 375);
            this.btnNext1.Name = "btnNext1";
            this.btnNext1.Size = new System.Drawing.Size(96, 24);
            this.btnNext1.TabIndex = 5;
            this.btnNext1.Text = "&Next";
            this.btnNext1.UseVisualStyleBackColor = false;
            this.btnNext1.Click += new System.EventHandler(this.btnNext1_Click);
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(16, 349);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(100, 23);
            this.label5.TabIndex = 3;
            this.label5.Text = "Output directory";
            // 
            // txtOutputDirectory
            // 
            this.txtOutputDirectory.Location = new System.Drawing.Point(128, 349);
            this.txtOutputDirectory.Name = "txtOutputDirectory";
            this.txtOutputDirectory.Size = new System.Drawing.Size(344, 20);
            this.txtOutputDirectory.TabIndex = 4;
            // 
            // tabPage2
            // 
            this.tabPage2.Controls.Add(this.btnClose);
            this.tabPage2.Controls.Add(this.btnStart);
            this.tabPage2.Controls.Add(this.rtb_EventLog);
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Size = new System.Drawing.Size(540, 414);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "Export";
            this.tabPage2.Visible = false;
            // 
            // btnClose
            // 
            this.btnClose.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnClose.ForeColor = System.Drawing.SystemColors.Info;
            this.btnClose.Location = new System.Drawing.Point(8, 376);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(96, 24);
            this.btnClose.TabIndex = 21;
            this.btnClose.Text = "&Close";
            this.btnClose.UseVisualStyleBackColor = false;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // btnStart
            // 
            this.btnStart.BackColor = System.Drawing.SystemColors.HotTrack;
            this.btnStart.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnStart.ForeColor = System.Drawing.SystemColors.Menu;
            this.btnStart.Location = new System.Drawing.Point(442, 376);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(96, 24);
            this.btnStart.TabIndex = 20;
            this.btnStart.Text = "&Start Export";
            this.btnStart.UseVisualStyleBackColor = false;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // rtb_EventLog
            // 
            this.rtb_EventLog.Location = new System.Drawing.Point(12, 8);
            this.rtb_EventLog.Name = "rtb_EventLog";
            this.rtb_EventLog.Size = new System.Drawing.Size(519, 360);
            this.rtb_EventLog.TabIndex = 11;
            this.rtb_EventLog.Text = "";
            // 
            // rdReportErrors
            // 
            this.rdReportErrors.Location = new System.Drawing.Point(8, 168);
            this.rdReportErrors.Name = "rdReportErrors";
            this.rdReportErrors.Size = new System.Drawing.Size(104, 24);
            this.rdReportErrors.TabIndex = 1;
            this.rdReportErrors.Text = "Report Errors";
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(600, 72);
            this.pictureBox1.TabIndex = 13;
            this.pictureBox1.TabStop = false;
            // 
            // formSharePointExtractor
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(555, 518);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.Settings);
            this.Controls.Add(this.rdReportErrors);
            this.Name = "formSharePointExtractor";
            this.Text = "SharePoint Products and Technologies Extractor";
            this.Settings.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new formSharePointExtractor());
		}
		/// <summary>
		/// RichTextBox Event Logger component
		/// </summary>
		public void AddTextToLogRtf(string incomingLogData)
		{
			try
			{
				incomingLogData = DateTime.Now.ToLongTimeString()+ ":  " + incomingLogData + "\n";
				

				//NOTE: replace rtf_eventlog with your RTF window, or text window, in your window app, to display log info.
				rtb_EventLog.AppendText(incomingLogData);
				rtb_EventLog.Focus();
				int textLength = rtb_EventLog.TextLength;
				rtb_EventLog.SelectionStart = textLength -1;
				rtb_EventLog.SelectionLength = 0;
				rtb_EventLog.ScrollToCaret();
				this.Refresh();
			}
			catch(Exception ex)
			{
				Debug.WriteLine("error while trying to write events incoming to AddTextToLogRtf function, error:" + ex.Message + ", in location:" + ex.TargetSite);
			}
		}
		private void IncomingEventLogData(object sender, SPEventArgs e)
		{
			AddTextToLogRtf(e.Message);
		}

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			rtb_EventLog.Clear();
			ErrorLevel level=ErrorLevel.Information;
			Logger.Init("export" + DateTime.Now.ToString("MMddHHmm",CultureInfo.InvariantCulture) + ".log",level);
			Logger.LogDataSendingEvent += new Logger.LogDataEventHandler(IncomingEventLogData);
			Extractor extractor=new Extractor();
			DataSet ds= new DataSet("Export Parameters");
			DataTable dt=ds.Tables.Add("Parameters");
			
			dt.Columns.Add("SiteURL");
			dt.Columns.Add("OutputDirectory");
			dt.Columns.Add("SiteName");
			dt.Columns.Add("List");
			dt.Columns.Add("Owner");
			dt.Columns.Add("Contact");
			dt.Columns.Add("IncludeSubWebs");
			dt.Columns.Add("RootContainerName");
			dt.Columns.Add("SiteType");
			dt.Columns.Add("DestSiteType");
			dt.Columns.Add("Folder");
			dt.Columns.Add("DateTimeThreshhold");
			dt.Columns.Add("ExtractDesign");
			dt.Columns.Add("ExtractUsers");
			dt.Columns.Add("ShowInSiteDir");
			dt.Columns.Add("DateThreshold");
			dt.Columns.Add("ExtractVersions");
            dt.Columns.Add("ExtractDoclibsOnly");
            dt.Columns.Add("ProcessGalleries");
            dt.Columns.Add("ExtractViews");
            
			DataRow newRow = dt.NewRow();

			// Set values in the columns:
			newRow["SiteURL"] = txtSiteURL.Text;
			newRow["OutputDirectory"] = txtOutputDirectory.Text;
			newRow["SiteName"] = txtNewName.Text;
			newRow["List"] = txtList.Text;
			newRow["Owner"] = "";
			newRow["Contact"] = "";
			newRow["includeSubWebs"] = chkExtractSubSites.Checked;
			newRow["RootContainerName"] = txtRoot.Text;
			newRow["SiteType"] = cmbSiteType.Text;
			newRow["DestSiteType"] = cmbDestSiteType.Text;
			newRow["Folder"] = txtFolder.Text;
			newRow["DateTimeThreshhold"] = DateTime.Now;
			newRow["ExtractDesign"] = chkExtractDesign.Checked;
			newRow["ExtractUsers"] = chkExtractUsers.Checked;
			newRow["ShowInSiteDir"] = chkSiteDir.Checked;
			if(chkUseTimeThreshold.Checked)
				newRow["DateThreshold"] = dtThreshhold.Value.ToString();
			else
				newRow["DateThreshold"] = DateTime.MinValue.ToString();
			newRow["ExtractVersions"] = chkVersions.Checked;
            newRow["ExtractDoclibsOnly"] = chkExtractDocLibsOnly.Checked;
            newRow["ProcessGalleries"] = chkProcessGalleries.Checked;
            newRow["ExtractViews"] = chkExtractViews.Checked;

			
			// Add the row to the rows collection.
			dt.Rows.Add(newRow);

			try
			{

				extractor.Process(ds);
				Logger.Log(ErrorLevel.Information,"\r\nDone");
			}
			catch(Exception Ex)
			{
				Console.WriteLine("Exception occurred :"+Ex.Message);
				Logger.Log(ErrorLevel.Error,"Exception occurred :"+Ex.Message);
			}
			Logger.LogDataSendingEvent -= new Logger.LogDataEventHandler(IncomingEventLogData);
			Logger.Close();
		
		}

		private void btnNext1_Click(object sender, System.EventArgs e)
		{
			Settings.SelectedIndex = 1;
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			DialogResult result = MessageBox.Show("Are you sure you'd like to exit?", "Close Application", MessageBoxButtons.YesNo,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly);
			if(result == DialogResult.Yes)
			{
				try 
				{
					

					// Create an instance of StreamWriter to write to a file.
					using(StreamWriter sw = new StreamWriter(configFile,false))
					{
						sw.WriteLine(txtSiteURL.Text);
						sw.WriteLine(txtNewName.Text);
						sw.WriteLine(txtOutputDirectory.Text);
						sw.WriteLine(txtRoot.Text);
						sw.WriteLine(cmbSiteType.Text);
						sw.WriteLine(cmbDestSiteType.Text);
						sw.WriteLine(txtFolder.Text);
						sw.WriteLine(DateTime.Now.ToUniversalTime().ToString());
						sw.WriteLine(chkExtractDesign.Checked.ToString());
						sw.WriteLine(chkExtractUsers.Checked.ToString());
						sw.WriteLine(txtList.Text);
						sw.WriteLine(chkExtractSubSites.Checked.ToString());
						sw.WriteLine(chkSiteDir.Checked.ToString());
						sw.WriteLine(chkUseTimeThreshold.Checked.ToString());
						sw.WriteLine(dtThreshhold.Value.ToString());
						sw.WriteLine(chkVersions.Checked.ToString());
						sw.WriteLine(chkExtractDocLibsOnly.Checked.ToString());
					
						sw.Flush();
						sw.Close();
					}
				}
				catch(IOException Ex)
				{
					Logger.Log(ErrorLevel.Information,"Could not write to config.dat. Error:"+Ex.Message );
				}
				this.Close();
			}
		}

		private void chkUseTimeThreshold_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkUseTimeThreshold.Checked)
				dtThreshhold.Enabled=true;
			else
				dtThreshhold.Enabled=false;

		}

        private void chkUseTimeThreshold_CheckedChanged_1(object sender, EventArgs e)
        {
            if (chkUseTimeThreshold.Checked)
                dtThreshhold.Enabled = true;
            else
                dtThreshhold.Enabled = false;
        }
	}
}
